#pragma once

#include <QObject>
#include <qstring.h>
#include <qvector.h>
#include <qmap.h>
#include <qnetworkaccessmanager.h>
#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qurl.h>

class http_client  : public QObject
{

	Q_OBJECT

public:
	static http_client* getInstance();
	static void deleteInstance();
	
	QNetworkReply* send_login_request(QString username, QString password);
	QNetworkReply* send_single_detect_request(QString filename);
	QNetworkReply* send_mutil_detect_request(QString file_path);
	QNetworkReply* send_video_detect_request(QString file_path);
	QNetworkReply* send_upload_dataset_request(QString dataset_name, QString file_path);
	QNetworkReply* send_download_dataset_request(QString file_path);
	QNetworkReply* send_list_dataset_request();
	QNetworkReply* send_clear_dataset_request();


	QNetworkReply* upload_dir(QString file_path, QUrl url);
	QNetworkReply* upload_file(QString file_path, QUrl url);

	int get_files(QString root_path, QStringList& files_list);
	int compressed_files(QString root_path);
	int coco_reply_parse_fromStr(QString raw_str, QMap<QString, QVector<QVector<int>>>& name2annot, QStringList& classes);

private:
	http_client(QObject *parent = nullptr);
	~http_client();

	const QString base_url = "http://www.liangchengmeijing.com:10003/";
	const QString detect_url = "http://140.210.199.246:8890/";
	const QString login_url = "userlogin/";
	const QString logout_url = "userlogout/";
	const QString register_url = "userregister/";
	const QString upload_datasets_url = "upload_dataset/";
	const QString download_dataset_url = "download_dataset/";
	const QString list_dataset_url = "list_dataset/";
	const QString clear_dataset_url = "clear_dataset/";

	const QString single_detect_url = "detect_demo/";
	const QString mutil_detect_url = "mutil_detect/";
	const QString video_detect_url = "video_detect/";

	static http_client* client_ptr;
	QNetworkAccessManager* manager = nullptr;
	
};
